home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)symload.c V1.27 3/13/95";
- #endif
- /*
- | file name - symload.c
- |===================================================================
- |
- | This program manages views created in DV-Draw. Objects are named
- | according to the filename of the view that should be displayed.
- | When a named object is selected the code finds the appropriate
- | view/drawport and draws it to the front.
- |
- | This program uses DV-Tools' symbol table routines to set up the
- | table of drawports and view names.
- |
- | The programs ends if the user selects the <q|Q> key or the
- | right mouse button. It also ends if the user selects an
- | object named "quit".
- |
- |===================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VTfundecl.h" /* VT routines (hash & symbol table) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
- #include "VUfundecl.h" /* VU routines (utilities) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "dvtooldemo.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
- /* Define global variables */
- OBJECT screen; /* display device, the window */
- DATASOURCELIST master_dsl; /* master data source list */
- SYMTABLE NameTable; /* symbol table */
-
- /* Functions defined in symload.c */
- DRAWPORT SetupDrawports V_P_((char *top_view_name));
- ADDRESS AddDrawports V_P_((OBJECT object, char *view_name, ADDRESS argblock));
- DRAWPORT GetNewDrawport V_P_((char *obj_name));
- void FreeDrawports V_P_((void));
-
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- * argv[2] - view filename
- */
-
- /* Define & initialize device name */
- char *device_name = DVDEVICE; /* default device name */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
- int event_req_status; /* status of event requests */
-
- /* Other variables */
- DRAWPORT current_drawport, /* how & where to display picture */
- next_drawport; /* how & where to display picture */
- char *obj_name = VIEW_NAME; /* name of view file to display */
- int Quit = NO; /* flag to quit program */
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- * TscErase: Erases the display device
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
- TscErase (screen);
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_KEYRELEASE |
- V_BUTTONPRESS | V_BUTTONRELEASE |
- V_RESIZE | V_EXPOSE | V_MOTIONNOTIFY,
- (ULONG) 0);
-
- /*
- * If the user supplies an initial view, create a drawport
- * with it; otherwise, use the default view name,
- * "dvtooldemo.v". Then draw the initial drawport.
- * If the current drawport has been assigned a NULL value
- * then there was a problem loading in the initial view.
- * Therefore, we exit the program.
- */
- if (argc > 2)
- obj_name = argv[2];
- current_drawport = SetupDrawports (obj_name);
- if (!current_drawport)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", obj_name);
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * TdlOpenData: Reads all data for one iteration
- * TdlReadData: Opens all files and processes
- * TdpDraw: Draw the contents of the drawport
- */
- TdlOpenData (master_dsl);
- TdlReadData (master_dsl);
- TdpDraw (current_drawport);
-
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_NO_WAIT.
- * Using this mode, VOloWinEventPoll
- * does not wait until a masked event
- * is generated.
- *
- * VUerHandleLocEvent: Service the event. This routine will check
- * if the event is used by any input objects.
- * that are in the view.
- */
- location = VOloWinEventPoll (V_NO_WAIT);
- if (location)
- {
- event_req_status = VUerHandleLocEvent (location);
- if (event_req_status == INPUT_UNUSED)
- {
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- case V_BUTTONPRESS:
- /*
- * Check button selected.
- * VOloButton: Returns the button that was pressed
- * TloGetSelectedObjectName: Get the name of the selected
- * object.
- * The left mouse button acts as the selection button. If
- * the object selected by the user has a name then compare
- * this name to the exit string "quit". If they match then
- * exit the program. Otherwise, use the object name as the
- * name of the next view file to display.
- */
- switch (VOloButton (location))
- {
- case 1:
- obj_name = TloGetSelectedObjectName (location);
- if (obj_name)
- {
- if (strcmp (obj_name, "quit") == 0)
- Quit = YES;
- else {
- next_drawport = GetNewDrawport (obj_name);
- if (next_drawport)
- {
- TdpErase (current_drawport);
- current_drawport = next_drawport;
- TdpDraw (current_drawport);
- }
- else{
- printf ("Could not load view from file ");
- printf ("%s.\n", obj_name);
- }
- }
- }
- break;
-
- case 3:
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- case V_MOTIONNOTIFY:
- default:
- break;
- }
- }
- }
-
- if (Quit == YES)
- break;
- TdlReadData (master_dsl);
- TdpDrawNext (current_drawport);
- }
-
- /*--------------------
- * Termination
- *
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TdlCloseData (master_dsl);
- FreeDrawports ();
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
-
- /*-----------------
- * SetupDrawports -- create the main drawport to display the
- * specified view. Use it's data source list for the master
- * data source. Create the symbol table which will hold the
- * created drawports. Then traverse all named objects in the
- * main view and create drawports for each named object which
- * corresponds to a view file.
- */
- DRAWPORT
- SetupDrawports (top_view_name)
- char *top_view_name;
- {
- DRAWPORT top_drawport;
- VIEW top_view;
- OBJECT drawing;
-
- /*
- * TviLoad: Load a view in from a file, the main view
- * is a user specified view filename or the
- * default view filename, dvtooldemo.v
- * TviGetDataSourceList: Get the data source list.
- *
- * Create a master data source list from the using the top view
- */
- top_view = TviLoad (top_view_name);
- if (!top_view)
- return NULL;
- master_dsl = TviGetDataSourceList (top_view);
-
- /*
- * TdpCreate: Create a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- */
- top_drawport = TdpCreate (screen, top_view,
- SCREEN_VIEWPORT, DRAWING_VIEWPORT);
-
- /*
- * VTstcreate: Create a symbol table
- * VTstsinsert: Inserts a node in the symbol table
- * TviGetDrawing: Gets drawing object
- * TdrForEachNamedObject: Traverse all named objects in drawing
- *
- * Create a symbol table of drawports which are keyed by their
- * view's name. Traverse all named objects in the top level view.
- * Attempt to load in a view using the object's name. If this is
- * successful create a drawport for this view and store the drawport
- * in the symbol table.
- */
- NameTable = VTstcreate ("Object Names and Drawports", (VTSTCOMPAREFUNPTR)NULL);
- VTstsninsert (NameTable, VUstrClone (top_view_name), (int *) top_drawport);
- drawing = TviGetDrawing (top_view);
- TdrForEachNamedObject (drawing, (TDRFOREACHNAMEDOBJFUNPTR)AddDrawports, (ADDRESS) NULL);
- return top_drawport;
- }
-
-
- /*---------------
- * AddDrawports -- loads the named view and creates a
- * drawport for it. Stores the new drawport in the symbol table.
- */
- /* ARGSUSED */
- ADDRESS
- AddDrawports (object, view_name, argblock)
- OBJECT object;
- char *view_name;
- ADDRESS argblock;
- {
- DRAWPORT drawport;
- VIEW view;
-
- /*
- * VTstkeyfind: Returns address of specified key in symbol table
- * TviMergeAddDataSource: Merges/add data sources.
- *
- * If the name of the object is "quit", there is no view to be
- * loaded, continue with the traversal. Otherwise, attempt to
- * load the view, and if successful, check to see if the view is
- * already in the symbol table. If not, add the views'
- * datasources to the master datasource list, create a drawport,
- * and add the drawport to the symbol table.
- */
- if (strcmp (view_name, "quit") == 0)
- return V_CONTINUE_TRAVERSAL;
- if (!VTstkeyfind (NameTable, view_name)){
- view = TviLoad (view_name);
- if (view)
- {
- TviMergeAddDataSources (view, master_dsl, DS_NAMEMATCH);
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
- VTstsninsert (NameTable, VUstrClone (view_name), (int *) drawport);
- }
- }
-
- return V_CONTINUE_TRAVERSAL;
- }
-
-
- /*-----------------
- * GetNewDrawport -- uses an object name to search the symbol table
- * for the next drawport to be displayed. If the view file name
- * does not exist in the symbol table then attempt to load in this
- * view file name, create a drawport for it and add the drawport to
- * the symbol table. Finally, return the drawport.
- */
- DRAWPORT
- GetNewDrawport (obj_name)
- char *obj_name;
- {
- SYMNODE symbol_node;
- DRAWPORT drawport;
- VIEW view;
-
- symbol_node = VTstkeyfind (NameTable, obj_name);
- if (!symbol_node)
- {
- view = TviLoad (obj_name);
- if (view)
- {
- TviMergeAddDataSources (view, master_dsl, DS_NAMEMATCH);
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT,
- DRAWING_VIEWPORT);
- VTstsninsert (NameTable, VUstrClone (obj_name), (int *) drawport);
- return drawport;
- }
- else
- return NULL;
- }
- else
- return (DRAWPORT) VTsnvalue (symbol_node);
- }
-
-
- /*----------------
- * FreeDrawports -- Destroy drawports and associated views
- * freeing allocated memory. Remove the nodes from the
- * symbol table and destroy the symbol table.
- */
- void FreeDrawports ()
- {
- DRAWPORT drawport;
- VIEW view;
-
- /*
- * VTstlen: Returns number of nodes in symbol table
- * VTstsnremove: Remove node from symbol table
- * TdpGetView: Gets view of a drawport
- * TdpDestroy: Destroy the drawport
- * TviDestroy: Destroy the view, freeing the allocated memory
- *
- * Traverse the symbol table. Obtain each drawport and
- * destroy it and it's view. Then remove the node from the
- * symbol table.
- */
- while (VTstlen (NameTable) > 0)
- {
- drawport = (DRAWPORT) VTsnvalue (VTstsnget (NameTable, 0));
- view = TdpGetView (drawport);
- TdpDestroy (drawport);
- TviDestroy (view);
- VTstsnremove (NameTable, VTstsnget (NameTable, 0));
- }
-
- /*
- * VTstdestroy: Destroy the symbol table.
- */
- VTstdestroy (NameTable);
- }
-